﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WUCAddOrUpdateArt.ascx.cs" Inherits="WebAppArtreve.views.shared.components.arts.WUCAddArt" %>
<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<%@ Register src="WUCArtImage.ascx" tagname="WUCArtImage" tagprefix="uc1" %>
<%@ Import Namespace="Krystalware.SlickUpload" %>
<%@ Register TagPrefix="kw" Assembly="Krystalware.SlickUpload" Namespace="Krystalware.SlickUpload.Web.Controls" %>

<%@ Register src="WUCArtImages.ascx" tagname="WUCArtImages" tagprefix="uc2" %>

<script type="text/javascript">
    function onFileCountChanged(data) {
        // Validate files
        validateFiles();

        var files = kw("<%=fileSelector.ClientID %>").get_Files();  
        var hasFiles = (files.length > 0);

        document.getElementById("<%=fileList.ClientID %>").style.display = (hasFiles > 0 ? "block" : "none");
        document.getElementById("uploadContainer").className = (hasFiles > 0 ? "small" : "initial");
        if(hasFiles < 1)
            document.getElementById("completeContainer").style.display = "none";

        var fileSelectorText = document.getElementById("fileSelectorText");

        if (fileSelectorText)
            fileSelectorText.innerHTML = (hasFiles > 0 ? "Select more files." : "Select files from your computer.");

        var folderSelectorText = document.getElementById("folderSelectorText");

        if (folderSelectorText)
            folderSelectorText.innerHTML = (hasFiles > 0 ? "Select another folder." : "Select a folder from your computer.");

        updateFileSize();

        var fileCountText;

        fileCountText = files.length + " file";

        if (files.length == 0 || files.length > 1)
            fileCountText += "s";

        document.getElementById("fileCount").innerHTML = fileCountText;
    }

    function updateFileSize(data) {
        var files = kw("<%=fileSelector.ClientID %>").get_Files();
        var totalFileSize = 0;

        for (var i = 0; i < files.length; i++) {
            var size = files[i].get_Size();

            if (size)
                totalFileSize += size;
        }

        var sizeString = kw.defaultFileSizeFormatter(totalFileSize);

        document.getElementById("fileSize").innerHTML = sizeString ? sizeString : "0 KB";
    }

    function onFileStart(file) {
        var fileEl = kw("<%=fileList.ClientID %>").getItemElementById(file.get_Id());
        var listEl = document.getElementById("<%=fileList.ClientID %>");

        listEl.scrollTop = fileEl.offsetTop - fileEl.offsetHeight;

        document.getElementById("completeContainer").style.display = "block";
    }

    function completeUpload() {
        document.getElementById("completeLink").style.display = "none";
        document.getElementById("completingIndicator").style.display = "block";
        document.getElementById("selectorContainer").style.display = "none";
        document.getElementById("<%=fileList.ClientID %>").style.bottom = "0px";

        kw("<%=slickUpload.ClientID %>").complete();
    }

    function validateFiles() {
        var selector = kw("<%=fileSelector.ClientID %>");
        var files = selector.get_Files();

        for (var i = 0; i < files.length; i++) {
            if (!files[i].get_IsValid()) {
                alert("Removing invalid file: " + files[i].get_Name());
                selector.remove_File(files[i]);
                return false;
            }
        }

        return true;
    }

    kw(function () {
        if (kw.support.dragDrop)
            document.getElementById("dropInstructions").style.display = "block";

        kw("<%=slickUpload.ClientID %>").start();
    });        
</script>
<div>    
    <fieldset>        
        <legend>Add a piece of art</legend>
        <hr />
        <br />
        <div class="art-image">            
            <!--<uc1:WUCArtImage ID="WUCArtImage1" runat="server" UsingQueryString="true" artPictureName="" Visible="false" />                                    
            <uc1:WUCArtImage ID="WUCArtImage2" runat="server" UsingQueryString="true" artPictureName="" Visible="false"/>     
            <uc1:WUCArtImage ID="WUCArtImage3" runat="server" UsingQueryString="true" artPictureName="" Visible="false"/>-->
            <asp:Image ID="ArtImage1" CssClass="imgArtView" runat="server" ImageUrl="" DescriptionUrl="" />                     
            <asp:Image ID="ArtImage2" CssClass="imgArtView" runat="server" ImageUrl="" DescriptionUrl=""/>                     
            <asp:Image ID="ArtImage3" CssClass="imgArtView" runat="server" ImageUrl="" DescriptionUrl=""/>                     
            <uc2:WUCArtImages ID="WUCArtImages" runat="server" />
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="lblArtName" 
                class="lblForm"
                runat="server" 
                Text="Artname:" 
                AssociatedControlID="txtArtName" />
            <asp:TextBox ID="txtArtName" class="input"
                runat="server" 
                MaxLength="50" 
                TextMode="SingleLine" Width="150px"/>
            <asp:RequiredFieldValidator ID="reqValtxtArtName"
                ControlToValidate="txtArtName"
                Text="*"
                runat="server" />
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="lblArtDescription" 
                class="lblForm"
                runat="server" 
                Text="Description:" 
                AssociatedControlID="txtArtDescription" />
            <asp:TextBox ID="txtArtDescription" class="input"
                runat="server" 
                MaxLength="50" 
                TextMode="MultiLine" Width="150px" BackColor="#535353" />
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="lblArtSize" 
                class="lblForm"
                runat="server" 
                Text="Size:" 
                AssociatedControlID="txtArtSize" />
            <asp:TextBox ID="txtArtSize" class="input"
                runat="server" 
                MaxLength="50" 
                TextMode="SingleLine" Width="150px"/>
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="lblArtPrice" 
                class="lblForm"
                runat="server" 
                Text="Price:" 
                AssociatedControlID="txtArtPrice" />
            <asp:TextBox ID="txtArtPrice" class="input"
                runat="server" 
                MaxLength="50" 
                TextMode="SingleLine" Width="150px"/>
            <asp:RequiredFieldValidator ID="reqValtxtArtPrice"
                ControlToValidate="txtArtPrice"
                Text="*"
                runat="server" />
            <asp:RegularExpressionValidator ID="regValtxtArtPrice"
                ControlToValidate="txtArtPrice"
                ValidationExpression="\d{1,}"
                EnableClientScript="true"
                ErrorMessage="Not a number!"
                runat="server" />
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="lblArtNumberOf" 
                class="lblForm"
                runat="server" 
                Text="Amount:" 
                AssociatedControlID="txtArtNumberOf" />
            <asp:TextBox ID="txtArtNumberOf" class="input"
                runat="server" 
                MaxLength="50" 
                TextMode="SingleLine" Width="150px"/>
            <asp:RequiredFieldValidator ID="reqValtxtArtNumberOf"
                ControlToValidate="txtArtNumberOf"
                Text="*"
                runat="server" />
            <asp:RegularExpressionValidator ID="regValtxtArtNumberOf"
                ControlToValidate="txtArtNumberOf"
                ValidationExpression="\d{1,}"
                EnableClientScript="true"
                ErrorMessage="Not a number!"
                runat="server" />
        </div>        
        <div class="formfieldrequired">
            <asp:Label ID="lblCategory" 
            class="lblForm"
            runat="server" 
            Text="Category:" 
            AssociatedControlID="ddlCategory" />
            <asp:DropDownList ID="ddlCategory" class="input"
            runat="server" DataSourceID="ODSCategoriesALL"
            AssociatedControlID="lblCategory" />
        </div>
        <div class="formfieldrequired">
            <asp:Label ID="LabelSpotlighted" 
                class="lblForm"
                runat="server" 
                Text="Place this item (again) in the spotlight (50 tokens):" 
                AssociatedControlID="cbxSpotlight" />
            <asp:CheckBox ID="cbxSpotlight" class="input"
                runat="server" Text="Yes" />
        </div>        
        <div class="formfieldrequired">             
        <asp:Panel ID="uploadPanel" runat="server">
    <div id="uploadContainer" class="initial">
        <div id="uploadTopContainer">
            <div id="completeContainer"><a href="javascript:completeUpload()" id="completeLink">Complete Upload</a><div id="completingIndicator" style="display:none">Completing Upload...</div></div>
            <span id="fileCount">0 files</span> (<span id="fileSize">0 KB</span>)        
        </div>
        <kw:FileList Id="fileList" FileSelectorId="fileSelector" runat="server"><ItemTemplate>                               
            <kw:FileListElement ID="FileListElement1" Element="FileName" runat="server" style="white-space:nowrap"/>
                <div style="white-space:nowrap;margin-left:30px">
                    <kw:FileListElement ID="FileListElement2" Element="FileSize" runat="server">(calculating)</kw:FileListElement>
                    <kw:FileListRemoveCommand ID="FileListRemoveCommand1" runat="server">[x]</kw:FileListRemoveCommand>
                </div>
                <div style="padding-right:20px;*width:150px;">
                    <kw:UploadProgressBar ID="UploadProgressBar1" runat="server"/>
                    
                </div>
                </ItemTemplate>
        </kw:FileList>            
        <div id="selectorContainer">
            <div id="dropInstructions" style="display:none">Drop files here.</div>
            <kw:FileSelector Id="fileSelector" UploadConnectorId="slickUpload" DropZoneId="uploadContainer" OnClientFileAdded="onFileCountChanged" OnClientFileRemoved="onFileCountChanged" OnClientFileValidated="updateFileSize" runat="server"><Template>                               
                <a href="javascript:;" style="margin-bottom:6px"><span id="fileSelectorText">Select files from your computer.</span></a>
                </Template>
                <FolderTemplate>                               
                    <a href="javascript:;"><span id="folderSelectorText">Select a folder from your computer.</span></a>
                </FolderTemplate>
            </kw:FileSelector>            
        </div>
    </div>
    <kw:UploadConnector Id="slickUpload" AutoCompleteAfterLastFile="false" AutoUploadOnSubmit="false" OnUploadComplete="slickUpload_UploadComplete" UploadProfile="slick" OnClientUploadFileStarted="onFileStart" runat="server"/>

        </asp:Panel>
        <asp:Panel ID="uploadResultPanel" runat="server" Visible="false">
            <h2>Upload Result</h2>
             <% if (slickUpload.UploadSession != null) { %>
                <p>Result: <%=slickUpload.UploadSession.State.ToString() %></p>
                <% if (slickUpload.UploadSession.State != UploadState.Error) { %>
                <p>Files Uploaded: <%=slickUpload.UploadSession.UploadedFiles.Count.ToString() %></p>
                <table class="results" width="99%" cellpadding="4" cellspacing="0">
                    <thead>
                        <tr>
                            <th align="left">Server Location</th>
                            <th align="left">Mime Type</th>
                            
                            <th align="left">Length (bytes)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="resultsRepeater" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td><%#((UploadedFile)Container.DataItem).ServerLocation.Replace("\\", "\\<wbr />") %></td>
                                    <td><%#((UploadedFile)Container.DataItem).ContentType %></td>
                                    
                                    <td><%#((UploadedFile)Container.DataItem).ContentLength %></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <% if (slickUpload.UploadSession.UploadedFiles.Count == 0) { %>
                        <tr class="nodata">
                            <td colspan="3">No files recieved.</td>
                        </tr>
                        <% } %>
                    </tbody>
                </table>
                <% } else { %>
                <p>Error Summary: <%=slickUpload.UploadSession.ErrorSummary %></p>
                <% } %>
            <% } else { %>
            <p>No upload recieved.</p>
            <% } %>    
        <p>
            <asp:LinkButton ID="newUploadButton" runat="server" CssClass="button"   onclick="newUploadButton_Click">
            <span><b class="icon newupload"></b> New Upload</span>        </asp:LinkButton>
                    <div style="clear:both"></div>
        </p>                                 
        </asp:Panel>          
        </div>
        <div class="formfieldrequired"><!-- CausesValidation="true" -->
            <asp:LinkButton ID="linkAddArt" CausesValidation="true" runat="server" onclick="linkAddArt_Click">Add art</asp:LinkButton>
        </div>
    </fieldset>
    <asp:ObjectDataSource ID="ODSCategoriesALL" 
    runat="server" 
    TypeName="CLibArtreve.bll.CategoryBLL"  
    SelectMethod="GetAllCategories"
    OnObjectCreating="ODSCategoriesALL_OnObjectCreating">
    </asp:ObjectDataSource>
</div>